home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / ps40sdk / examples / selection / selectorama / selectoramauiwin.c < prev   
Encoding:
C/C++ Source or Header  |  1996-09-20  |  8.3 KB  |  305 lines

  1. /*
  2.     File: SelectoramaUIWin.c
  3.  
  4.     Copyright (c) 1991-6, Adobe Systems Incorporated.
  5.     All rights reserved.
  6.  
  7.     C source file for Windows specific code for Selection example.
  8. */
  9.  
  10. #include "Selectorama.h"
  11.  
  12. /*****************************************************************************/
  13.  
  14. BOOL WINAPI SelectionProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam); // Win32 Change
  15. Boolean Validate (GPtr globals, const HWND hDlg, int *item);
  16.  
  17. /*****************************************************************************/
  18.  
  19. void DoAbout (GPtr globals)
  20. {
  21.     ShowAbout((AboutRecordPtr)gStuff, hDllInstance, AboutID);
  22. }
  23.  
  24. /****************************************************************************/
  25. /* Example for ShowAlert() function which takes a string ID as parameter    */
  26. /* and displays a message box                                               */
  27. /****************************************************************************/
  28.  
  29. short ShowAlert (short stringID)
  30. {
  31.     char szMessage[256];
  32.     char szTitle[128];
  33.  
  34.     LoadString(hDllInstance, stringID, szMessage, sizeof szMessage);
  35.     LoadString(hDllInstance, 2, szTitle, sizeof szTitle);
  36.     return  ( MessageBox(NULL, szMessage, szTitle, MB_OK | MB_ICONHAND) );
  37. }
  38.  
  39. /*****************************************************************************/
  40. // Because we want to wait until the user changes the focus
  41. // from an EditText field to something else, and because we
  42. // want to ignore validation if the user Cancels, this routine
  43. // does round of validating fields if it's been flagged.
  44.  
  45. Boolean Validate (GPtr globals, const HWND hDlg, int *item)
  46. {
  47.     int32    x = 0;
  48.     Boolean retn = true;
  49.     short    numberErr = noErr;
  50.  
  51.     switch (*item)
  52.     {
  53.         case  kPercentEdit: // user moving to something not the edit text
  54.             numberErr = FetchNumber(hDlg, 
  55.                                kPercentEdit, 
  56.                                kPercentMin, 
  57.                                kPercentMax, 
  58.                                &x);
  59.  
  60.             if (numberErr != noErr)
  61.             { // shows alert if there's an error
  62.                 AlertNumber(hDlg,
  63.                             kPercentEdit,
  64.                             kPercentMin,
  65.                             kPercentMax,
  66.                             &x,
  67.                             hDllInstance,
  68.                             AlertID,
  69.                             numberErr);
  70.                 retn = false; // had to pop an error, stay here
  71.             }
  72.  
  73.             // gPercent = (short)x;
  74.  
  75.             break;
  76.     }
  77.     *item = 0;
  78.     return retn;
  79. }
  80.  
  81. /*****************************************************************************/
  82.  
  83. BOOL WINAPI SelectionProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) // Win32 Change
  84. {
  85.     int                item = 0;
  86.     int                cmd = 0;
  87.     int32            x = 0;
  88.     short            numberErr = noErr;
  89.     static GPtr        globals=NULL;          /* need to be static */
  90.     static int        lastItem = 0;
  91.     // static short    lastPercent = gPercent;
  92.     
  93.     switch (wMsg)
  94.     {
  95.  
  96.         case  WM_INITDIALOG:
  97.  
  98.             /* set up globals    */
  99.             globals = (GPtr) lParam;
  100.             
  101.             CenterDialog(hDlg);
  102.             
  103.             SetRadioGroupState(hDlg,
  104.                                kUseRadio1, 
  105.                                kUseRadioLast, 
  106.                                kUseRadio1 + gWhatChannels);
  107.             SetRadioGroupState(hDlg, 
  108.                                kFirstItem, 
  109.                                kLastItem, 
  110.                                kFirstItem + gWhatArea);
  111.             SetRadioGroupState(hDlg,
  112.                                kCreateRadio1,
  113.                                kCreateRadioLast, 
  114.                                kCreateRadio1 + gCreate);
  115.             ShowHideItem(hDlg, kPercentStatic, (gWhatArea == iSelectRandom));
  116.             ShowHideItem(hDlg, kPercentEdit, (gWhatArea == iSelectRandom));
  117.             ShowHideItem(hDlg, kPercentSymbol, (gWhatArea == iSelectRandom));
  118.             StuffNumber(hDlg, kPercentEdit, gPercent);
  119.             if (gWhatArea == iSelectRandom) SelectTextItem(hDlg, kPercentEdit);
  120.             
  121.             /* fall into WM_PAINT */
  122.         case WM_PAINT:
  123.             return FALSE;
  124.             break;
  125.  
  126.         case WM_COMMAND:
  127.               item = COMMANDID (wParam);
  128.             cmd = HIWORD (wParam);
  129.  
  130.             switch (item)
  131.             {
  132.                 case ok:
  133.                     if (cmd == BN_CLICKED)
  134.                     {
  135.                         gWhatChannels = GetRadioGroupState(hDlg, kUseRadio1, kUseRadioLast)
  136.                                         - kUseRadio1;
  137.                         gWhatArea = GetRadioGroupState(hDlg, kFirstItem, kLastItem)
  138.                                     - kFirstItem;
  139.                         gCreate = GetRadioGroupState(hDlg, kCreateRadio1, kCreateRadioLast)
  140.                                   - kCreateRadio1;
  141.                         if (gWhatArea == iSelectRandom)
  142.                         {
  143.                             lastItem = kPercentEdit; // force validate
  144.                             if (Validate(globals, hDlg, &lastItem))
  145.                             {
  146.                                 FetchNumber(hDlg, kPercentEdit, kPercentMin, kPercentMax, &x);
  147.                                 gPercent = (short)x;
  148.                                 EndDialog(hDlg, item); 
  149.                                 return TRUE;
  150.                             }
  151.                         }
  152.                         else // no iSelectRandom
  153.                         {
  154.                             EndDialog(hDlg, item);
  155.                             return TRUE;
  156.                         }
  157.                     }
  158.                     else Validate(globals, hDlg, &lastItem);
  159.                     break;
  160.                 case cancel:
  161.                     if (cmd == BN_CLICKED)
  162.                     {
  163.                         gResult = userCanceledErr;
  164.                         EndDialog(hDlg, item);
  165.                     }
  166.                     break;
  167.                 case kPercentEdit:
  168.                     if (Validate(globals, hDlg, &lastItem))
  169.                     {
  170.                         if (cmd == EN_KILLFOCUS)
  171.                             lastItem = kPercentEdit; // validate will get this
  172.                         else if (cmd == EN_CHANGE)
  173.                         {
  174.                             numberErr = FetchNumber(hDlg,
  175.                                                     kPercentEdit,
  176.                                                     kPercentMin,
  177.                                                     kPercentMax,
  178.                                                     &x);
  179.                             if (numberErr == noErr && x != gPercent)
  180.                             { // different number, update
  181.                                 // gPercent = (short)x;
  182.                             }
  183.                         }
  184.                     }
  185.                     break;
  186.                 default:
  187.                     if (item >= kUseRadio1 && item <= kUseRadioLast)
  188.                     {
  189.                         if (Validate(globals, hDlg, &lastItem))
  190.                         {
  191.                             if (cmd == BN_CLICKED)
  192.                             {
  193.                                 SetRadioGroupState(hDlg, kUseRadio1, kUseRadioLast, item);
  194.                             }
  195.                         }
  196.                     }
  197.                     else if (item >= kCreateRadio1 && item <= kCreateRadioLast)
  198.                     {
  199.                         if (Validate(globals, hDlg, &lastItem))
  200.                         {
  201.                             if (cmd == BN_CLICKED)
  202.                                 SetRadioGroupState(hDlg, kCreateRadio1, kCreateRadioLast, item);
  203.                         }
  204.                     }
  205.                     else if (item >= kFirstItem && item <= kLastItem)
  206.                     {
  207.                         if (Validate(globals, hDlg, &lastItem))
  208.                         {
  209.                             if (cmd == BN_CLICKED)
  210.                             {
  211.                                 SetRadioGroupState(hDlg, kFirstItem, kLastItem, item);
  212.                                 ShowHideItem(hDlg, kPercentStatic, (item == (iSelectRandom + kFirstItem)));
  213.                                 ShowHideItem(hDlg, kPercentEdit, (item == (iSelectRandom + kFirstItem)));
  214.                                 ShowHideItem(hDlg, kPercentSymbol, (item == (iSelectRandom + kFirstItem)));
  215.                                 if (item == (iSelectRandom + kFirstItem)) SelectTextItem(hDlg, kPercentEdit);
  216.                             }
  217.                         }
  218.                     }
  219.                     return FALSE;
  220.                     break;
  221.             } /* switch (item) */ 
  222.             break;
  223.         default:
  224.             return FALSE;
  225.             break;
  226.     } /* switch (wMsg) */
  227.     return TRUE;
  228. }
  229.  
  230. /*****************************************************************************/
  231. Boolean DoParameters (GPtr globals)
  232. {
  233.  
  234.     int                nResult = noErr;
  235.     PlatformData    *platform;
  236.     
  237.     platform = ((SelectionRecordPtr) gStuff)->platformData;
  238.  
  239.     /* Query the user for parameters. */
  240.  
  241.     nResult = DialogBoxParam(hDllInstance,
  242.                        (LPSTR)"SELECTIONPARAM",
  243.                        (HWND)platform->hwnd,
  244.                        (FARPROC)SelectionProc,
  245.                         (LPARAM)globals);
  246.  
  247.     return (nResult == ok); // could be -1
  248. }
  249.  
  250. /*****************************************************************************/
  251.  
  252. /* Initialization and termination code for window's dlls. */
  253.  
  254. // Win32 Change
  255. #ifdef WIN32
  256.  
  257. // Every 32-Bit DLL has an entry point DLLInit
  258.  
  259. BOOL APIENTRY DLLInit(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
  260. {
  261.  
  262.     if (fdwReason == DLL_PROCESS_ATTACH)
  263.         hDllInstance = hInstance;
  264.  
  265.     return TRUE;   // Indicate that the DLL was initialized successfully.
  266. }
  267.  
  268. #else
  269. /* ------------------------------------------------
  270.  *   Code from Borland's window's dll example code.
  271.  * ------------------------------------------------
  272.  */
  273. #if defined(__BORLANDC__)
  274. // Turn off warning: Parameter '' is never used; effects next function only
  275. #pragma argsused
  276. #endif
  277.  
  278. // Every DLL has an entry point LibMain and an exit point WEP.
  279. int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
  280.                                    WORD wHeapSize, LPSTR lpszCmdLine )
  281. {
  282.     // Required when using Zortech; causes blink to include startup code
  283.     extern __acrtused_dll;
  284.  
  285.     // The startup code for the DLL initializes the local heap (if there is one)
  286.     // with a call to LocalInit which locks the data segment.
  287.     if ( wHeapSize != 0 )
  288.         UnlockData( 0 );
  289.  
  290.     hDllInstance = hInstance;
  291.     return 1;   // Indicate that the DLL was initialized successfully.
  292. }
  293.  
  294. int FAR PASCAL WEP(int nParam)
  295. {
  296.     switch  (nParam) 
  297.     {
  298.       case  WEP_SYSTEM_EXIT: // System shutdown in progress
  299.       case  WEP_FREE_DLL   : // DLL use count is 0
  300.       default :              // Undefined;  ignore
  301.             return  1;
  302.     }
  303. }
  304. #endif
  305.